<template>
	<view class="announcement">
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(index)">
				<view class="top flex_end_b">
					<view class="title">{{item.title}}</view>
					<view class="time">{{item.update_time}}</view>
				</view>
				<view class="content u-line-2">{{item.jianjie}}</view>
			</view>
		</view>
		
		<view class="noContent" v-if="list.length == 0">
		  <image class="noContentImage" mode="widthFix" src="/static/noLive.png"></image>
		</view>
	</view>
</template>

<script>
	var util = require('../../common/util.js');
	export default {
		data() {
			return {
				cate_id:0,
				p: 1,
				is_loading: false,
				is_more: true,
				list: []
			}
		},
		onLoad(opt) {
			this.cate_id = opt.cate_id;
			uni.setNavigationBarTitle({
				title:opt.title
			});
			this.loadData();
		},
		onReachBottom() {
			if (!this.is_loading) {
				if (!this.is_more) {
					util.toast("没有更多数据了");
					return false;
				}
				this.p = parseInt(this.p) + 1;
				this.loadData();
			}
		},
		methods: {
			loadData: function() {
				// 加载数据
				var that = this;
				this.is_loading = true;
				let data = {
					'p': this.p,
					cate_id:this.cate_id
				};
				util.requestPost("api.php/home/articleList", data, function(res) {
					let is_more = false;
					if (res.data.list.length >= 15) {
						is_more = true;
					}
					if (that.p == 1) {
						that.list = res.data.list;
					} else {
						that.list = that.list.concat(res.data.list);
					}
			
					that.is_loading = false;
					that.is_more = is_more;
				});
			},
			detail(index){
				let notice = this.list[index];
				if(notice.out_link){
					uni.navigateTo({
						url:"/pages/openUrl/openUrl?openUrl="+notice.out_link+"&title="+notice.title
					});
				}else{
					uni.navigateTo({
						url: '/pagesB/index/announcementDetail?id='+notice.id
					});
				}
			}
		}
	}
</script>

<style scoped lang="scss">
.announcement {
	min-height: 100%;
	background-color: #f4f4f4;
	.list {
		padding: 20rpx;
		.item {
			background-color: #FFFFFF;
			border-radius: 8rpx;
			margin-bottom: 20rpx;
			padding: 32rpx;
			&:last-of-type {
				margin-bottom: 0;
			}
			.top {
				vertical-align: bottom;
				.title {
					font-size: 30rpx;
					font-weight: 600;
				}
				.time {
					font-size: 24rpx;
					color: #999999;
				}
			}
			.content {
				font-size: 24rpx;
				color: #999999;
				margin-top: 12rpx;
			}
		}
	}
}
</style>
